package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.CollectedData;
import com.ruoyi.business.service.ICollectedDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采集数据Controller
 * 
 * @author asher
 * @date 2021-12-12
 */
@RestController
@RequestMapping("/business/collected_data")
public class CollectedDataController extends BaseController
{
    @Autowired
    private ICollectedDataService collectedDataService;

    /**
     * 查询采集数据列表
     */
    @PreAuthorize("@ss.hasPermi('business:collected_data:list')")
    @GetMapping("/list")
    public TableDataInfo list(CollectedData collectedData)
    {
        startPage();
        List<CollectedData> list = collectedDataService.selectCollectedDataList(collectedData);
        return getDataTable(list);
    }

    /**
     * 导出采集数据列表
     */
    @PreAuthorize("@ss.hasPermi('business:collected_data:export')")
    @Log(title = "采集数据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CollectedData collectedData)
    {
        List<CollectedData> list = collectedDataService.selectCollectedDataList(collectedData);
        ExcelUtil<CollectedData> util = new ExcelUtil<CollectedData>(CollectedData.class);
        return util.exportExcel(list, "采集数据数据");
    }

    /**
     * 获取采集数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:collected_data:query')")
    @GetMapping(value = "/{cardId}")
    public AjaxResult getInfo(@PathVariable("cardId") String cardId)
    {
        return AjaxResult.success(collectedDataService.selectCollectedDataByCardId(cardId));
    }

    /**
     * 新增采集数据
     */
    @PreAuthorize("@ss.hasPermi('business:collected_data:add')")
    @Log(title = "采集数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CollectedData collectedData)
    {
        return toAjax(collectedDataService.insertCollectedData(collectedData));
    }

    /**
     * 修改采集数据
     */
    @PreAuthorize("@ss.hasPermi('business:collected_data:edit')")
    @Log(title = "采集数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CollectedData collectedData)
    {
        return toAjax(collectedDataService.updateCollectedData(collectedData));
    }

    /**
     * 删除采集数据
     */
    @PreAuthorize("@ss.hasPermi('business:collected_data:remove')")
    @Log(title = "采集数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cardIds}")
    public AjaxResult remove(@PathVariable String[] cardIds)
    {
        return toAjax(collectedDataService.deleteCollectedDataByCardIds(cardIds));
    }
}
